import { financeJson } from '../json/fiance';
import Logger from '../../../util/Logger';
import { observer } from '@kit.TelephonyKit';

export interface  AA {
  name:string;
  age:number;
}

export interface fianceObjModule{
  blockType: string;
  navListData?: Array<navList>;
  tabBannerListData?: Array<tabData>;
  highPrdListData?: Array<highPrd>;
  steadyPrdListData?: Array<steadyPrd>;
  depositPrdListData? :Array<depositPrd>
}

// nav模块模型
export interface navList{
  blockName: string,
  icon: string
}
// tab模块模型
export interface tabData{
  blockName: string,
  cateGroy: Array<tabPrd>
}

// tab模块产品模型
export interface tabPrd {
  title: string,
  blockName: string,
  subTabTitle: string,
  pop: string,
  prdName: string,
  rate: string,
  desc: string,
  btn: string
}

// @Observed
// export class tabDataClass {
//   public blockName: string;
//   public cateGroy: tabPrdClass;
//   constructor(blockName: string, cateGroy: tabPrdClass) {
//     this.blockName = blockName;
//     this.cateGroy = cateGroy;
//   }
// }

// 进阶投资
export interface highPrd{
  prdName: string,
  rate: string,
  subTitle: string,
  rateDesc: string,
  desc: string
}

// 稳健投资
export interface steadyPrd{
  prdName?: string,
  rate?: string,
  subTitle?: string,
  rateDesc?: string,
  desc?: string,
  pop?: string,
  tip?: string
}

export interface depositPrd{
  prdName: string,
  rate: string,
  subTitle: string,
  rateDesc: string,
  desc: string,
  pop: string,
  nameIcon: boolean
}

export interface commonPrdModle{
  prdName?: string,
  rate?: string,
  subTitle?: string,
  rateDesc?: string,
  desc?: string,
  pop?: string,
  tip?: string
  nameIcon?: boolean
}




// 全局接口数据处理，使用type筛选出模块需要的数据
export interface resultList{
  response: Object
}

export class resList {
  blockType: string;
  dataList: Array<commonObj>
  constructor(blockType: string, dataList: Array<commonObj>) {
    this.blockType = blockType;
    this.dataList = dataList;
  }
}

export interface commonObj {
  "blockName"?: string,
  "nodeAddition"?: string,
  "productValue"?: string,
  "resourceUrl"?: string,
  "blockType": string,
  "fatherId": number,
  "linkUrl": string,
  "id": number,
  "blockOrder": number,
  "productInfo": string
}

export interface getUrl{
  url: string
}

// 处理接口返回数据
export function handleRes(){
  const res = financeJson()
  let datatList = [];
  let resList:Array<resList>;
  const data = res.response.data
  if(data && data.blockList && data.productList){
    data.blockList.forEach((item)=>{
      datatList = []
      const id = item?.id;
      const blockType = `SUB${item.blockType}`
      data.productList.forEach((obj)=>{
        if(obj.fatherId == id && obj.blockType == blockType){
          datatList.push(obj)
        }
      })
      resList.push({blockType: item.blockType, dataList: datatList})
    })
  }
  return resList;
}

export class  NavObject {
  blockName: String = ""
}

// 财富页导航金刚位的类
class NavLit {
  public iconName?: string;
  public blockName: string

  constructor(iconName: string, blockName: string) {
    this.iconName = iconName;
    this.blockName = blockName;
  }
}

export enum FianceEnum {
  Nav = "FUNCTION"
}


